package com.yuanzong.wuliu.service.system.user.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yuanzong.wuliu.common.vo.ApiResultPage;
import com.yuanzong.wuliu.mapper.system.user.SystemUserMapper;
import com.yuanzong.wuliu.model.system.user.SystemUser;
import com.yuanzong.wuliu.model.system.user.query.*;
import com.yuanzong.wuliu.service.system.user.ISystemUserService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service("systemUserService")
public class SystemUserServiceImpl extends ServiceImpl<SystemUserMapper, SystemUser> implements ISystemUserService {

    // 逻辑删除
    protected static final boolean logicalDeleted = false;

    @Autowired
    private SystemUserMapper systemUserMapper;

    //========================================================================================//
    // Service服务接口操作
    //========================================================================================//

    @Override
    public List<SystemUser> querySubject(SystemUserListQuery query) throws Exception {
        List<SystemUser> systemUserList = null;
        QueryWrapper<SystemUser> queryWrapper = new QueryWrapper<>();
        systemUserList = super.getBaseMapper().selectList(queryWrapper);
        return systemUserList;
    }

    @Override
    public ApiResultPage<SystemUser> pageSubject(SystemUserPageQuery query) throws Exception {
        ApiResultPage<SystemUser> systemUserPageList = null;
        Page<SystemUser> systemUserPage = new Page<>(query.getPageNum(), query.getPageSize());
        QueryWrapper<SystemUser> queryWrapper = new QueryWrapper<>();
        if (StringUtils.isNotEmpty(query.getNoUsername())) {
            queryWrapper.ne("username", query.getNoUsername());
        }
        systemUserPage = super.baseMapper.selectPage(systemUserPage, queryWrapper);
        systemUserPageList = ApiResultPage.create(query.getPageNum(), query.getPageSize(), systemUserPage);
        return systemUserPageList;
    }

    @Override
    public SystemUser queryByUsername(String username) throws Exception {
        QueryWrapper<SystemUser> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("username", username);
        return this.baseMapper.selectOne(queryWrapper);
    }

    //========================================================================================//
    // HTTP服务接口操作
    //========================================================================================//

    //========================================================================================//
    // extend methods
    //========================================================================================//


    //========================================================================================//
    // The end
    //========================================================================================//

}
